#!/bin/bash
set -e

#>>-----------------------------------------------------------------------------------
#顶层项目目录
export PROJECT_TOPDIR=$PWD
#顶层当前配置文件
export CURCFG_FILE=${PROJECT_TOPDIR}/.curconfig.sh
#-------------------------------------------------------------------------------------

#>>env--------------------------------------------------------------------------------
#设置颜色函数
source ${PROJECT_TOPDIR}/a.OEMKIT/scripts/dugi.000.colorsetup.sh
#导入公共变量
source ${PROJECT_TOPDIR}/a.OEMKIT/scripts/dugi.001.envsetup_common.sh
#导入平台变量
source ${PROJECT_TOPDIR}/a.OEMKIT/scripts/dugi.002.envsetup_platform.sh
#-------------------------------------------------------------------------------------

#检查当前机型配置
if [ ! -f ${CURCFG_FILE} ]; then
	serro "检查当前配置文件... [失败]"
	exit 1
fi

source ${CURCFG_FILE}

#重新确定配置文件名称和路径
update_copy_env
update_boot_env
update_kern_env
update_knfs_env
update_rtfs_env
relocate_imgbin_defname

main_proc()
{	
	#配置编译环境
	check_env
	if [ ! -d ${DEVKIT_TOPDIR} ]; then
		mkdir -p ${DEVKIT_TOPDIR}
	fi
	curtime=$(date +%Y%m%d)
	export DEVKIT_SUBDIR_NAME="U${OEMDEV_CUR_TYPE}_DEVKIT_${curtime}"
	export DEVKIT_SUBDIR_PATH=${DEVKIT_TOPDIR}/${DEVKIT_SUBDIR_NAME}
	if [ ! -d ${DEVKIT_SUBDIR_PATH} ]; then
		mkdir -p ${DEVKIT_SUBDIR_PATH}
	fi
	
	sinfo "拷贝GCCKIT ... [开始]"
	cp -rf ${GCCKIT_TOPDIR} ${DEVKIT_SUBDIR_PATH}/
	sdone "拷贝GCCKIT ... [完成]"

	sinfo "拷贝OEMKIT ... [开始]"
	cp -rf ${OEMKIT_TOPDIR} ${DEVKIT_SUBDIR_PATH}/
	sdone "拷贝OEMKIT ... [完成]"

	sinfo "拷贝APPKIT ... [开始]"
	cp -rf ${APPKIT_TOPDIR} ${DEVKIT_SUBDIR_PATH}/
	sdone "拷贝APPKIT ... [完成]"

	sinfo "拷贝OTAKIT ... [开始]"
	cp -rf ${OTAKIT_TOPDIR} ${DEVKIT_SUBDIR_PATH}/
	sdone "拷贝OTAKIT ... [完成]"

	sinfo "打包DEVKIT ... [开始]"

	cd ${DEVKIT_TOPDIR}
	tar cjvf ${DEVKIT_SUBDIR_NAME}.tar.gz ${DEVKIT_SUBDIR_NAME}
	if [ $? -ne 0 ]; then
		serro "打包DEVKIT: ${DEVKIT_SUBDIR_NAME} ... [失败]"
		return 1
	fi
	sdone "打包DEVKIT ${DEVKIT_SUBDIR_NAME} ... [完成]"
	cd -> /dev/null
	return 0
}
main_proc  $@
